package com.dq.health.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dq.health.dao.outpatient.OutpatientOrderMapper;
import com.dq.health.dao.user.UserBaseInfoMapper;
import com.dq.health.dto.request.outpatient.QueryOutpatientParam;
import com.dq.health.dto.response.outpatient.OutpatientOrderInfo;
import com.dq.health.entity.outpatient.OutpatientOrder;
import com.dq.health.service.IAPIOutpatientService;

/**
 * <>
 *
 * @Author: chenxin
 * @Date: 2021/5/17
 */
@Service
public class OutpatientServiceImpl implements IAPIOutpatientService {

    @Resource
    OutpatientOrderMapper outpatientOrderMapper;

    @Resource
    UserBaseInfoMapper userBaseInfoMapper;

    @Override
    public IPage<OutpatientOrderInfo> queryList(QueryOutpatientParam param) {
        return null;
    }

    @Override
    public OutpatientOrderInfo queryInfoById(Long id) {
        OutpatientOrder outpatientOrder = outpatientOrderMapper.selectById(id);
        OutpatientOrderInfo outpatientOrderInfo = new OutpatientOrderInfo();
        outpatientOrderInfo.setOutpatientOrderId(outpatientOrder.getOutpatientOrderId());
        outpatientOrderInfo.setOutpatientOrderSn(outpatientOrder.getOutpatientOrderSn());
        outpatientOrderInfo.setUserId(outpatientOrder.getUserId());
        outpatientOrderInfo.setUserName(userBaseInfoMapper.selectById(outpatientOrder.getUserId()).getUserName());
        outpatientOrderInfo.setDoctorUserId(outpatientOrder.getDoctorUserId());
        outpatientOrderInfo.setDoctorUserName(userBaseInfoMapper.selectById(outpatientOrder.getDoctorUserId()).getUserName());
        outpatientOrderInfo.setOrderTime(outpatientOrder.getOrderTime());
        outpatientOrderInfo.setOrderStatus(outpatientOrder.getOrderStatus().intValue());
        outpatientOrderInfo.setCreateTime(outpatientOrder.getCreateTime());
        return outpatientOrderInfo;
    }

    @Override
    public void updateOrderStatus(Long id, Long operationUserId, Integer status) {
        OutpatientOrder outpatientOrder = outpatientOrderMapper.selectById(id);
        outpatientOrder.setOrderStatus(status.byteValue());
        outpatientOrderMapper.updateById(outpatientOrder);
    }

    @Override
    public Long addOutpatientOrder() {
        return null;
    }
}
